<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>simpleCalculator</title>
</head>
<body>
<form action="calculator.php" method="post">
    <label>
        数字1：
        <input type="text" name="num1">
    </label>
    <label>
        <select name="option" id="">
            <option value="+">+</option>
            <option value="-">-</option>
            <option value="*">x</option>
            <option value="/">÷</option>
            <option value="**">x²</option>
        </select>
    </label>
    <label>
        数字2：
        <input type="text" name="num2">
    </label>
    <input type="submit" value="计算">
</form>
</body>
</html>
<?php
error_reporting( E_ALL ^ E_NOTICE );
$num1 = $_POST['num1'];
$num2 = $_POST['num2'];
$op = $_POST['option'];
function checkNull($num1, $num2)
{
    if ($num1 !== '' and $num2 !== '') {
        return true;
    } else {
        echo "输入不能为空";
        return false;
    }
}

function allNum($num1, $num2)
{
    if (is_numeric( $num2 ) and is_numeric( $num1 )) {
        return true;
    } else {
        echo "必须输入纯数字";
        return false;
    }
}

if (checkNull( $num1, $num2 ) and allNum( $num1, $num2 )) {
    switch ($op) {
        case "+":
            $result = $num2 + $num1;
            break;
        case "-":
            $result = $num1 - $num2;
            break;
        case "*":
            $result = $num1 * $num2;
            break;
        case "/":
            if ($num2 != 0) {
                $result = $num1 / $num2;
            } else {
                echo "除数不能为0";
            }
            break;
        case "**":
            $result = $num1 ** $num2;
    }
}
echo "<br>";
echo "结果是:" . $result;
?>